package cn.liontalk.concurrent.automtic;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.Random;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class StreamListTest {
    static List<String> list = new ArrayList<>();

    static {
        list.add("zhou");
        list.add("tong");
        list.add("hello");
        list.add("test");
        list.add("putty");
        list.add("apple_pear");
    }


    public static void main(String[] args) {
//        System.out.println(list.size());
//        boolean result = list.stream().anyMatch(s -> s.contains("hello"));
//        List<String> strings = list.stream().filter(s -> s.length() <= 4).collect(Collectors.toList());
//        System.out.println(strings);
//
//
//        System.out.println(
//                list.stream()
//                        .filter(s -> s.length() <= 4)
//                        .map(s -> s.toUpperCase())
//                        .collect(Collectors.toList()));
//
//        System.out.println(list.stream().filter(s->s.length()<=4).map(String::toUpperCase).collect(Collectors.toList()));
        List<String> list = new ArrayList<>();

        for (int i = 0; i < 10000000; i++) {
            list.add("zhou" + i);
        }

        long start = System.currentTimeMillis();
        System.out.println("开始时间==>::" + start);
        System.out.println(getTest(list));
//        list =  list.stream().filter(s->s.length()>=6).collect(Collectors.toList());
//        System.out.println(list);
        System.out.println("结束时间==>::" + (System.currentTimeMillis() - start));

    }

    // 9999990
    // 结束时间==>::9012

    private static List<String> getTest(List<String> list) {
        List<String> result = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            int length = list.get(i).length();
            if (length >= 6) {
                result.add(list.get(i));
            }
        }
        System.out.println("result size===>> "+result.size());
        return result;
    }
}
